/*
 * @Description: 用户权限相关 API
 * @Version: 1.0
 * @Author: Yuanjy
 * @Date: 2020-03-09 20:41:15
 * @LastEditors: Yuanjy
 * @LastEditTime: 2020-05-18 16:34:45
 */
import createAPI from '@/utils/axios'

const permission = {

  // 授权信息相关
  auth: {
    //企业微信授权登录
    wwxLogin: config => createAPI('/admin/v1/auth/wwx-login', 'POST', config),
    //获取预授权链接
    preAuthUrl: () => createAPI('/admin/v1/auth/pre-auth-url', 'GET', {}),
    //获取第三方应用的链接
    getThirdLoginUrl: () => createAPI('/admin/v1/auth/third-login-url', 'GET', {}),
    //企业授权给第三方应用
    authEnterprise: config => createAPI('/admin/v1/auth/auth-enterprise', 'POST', config),
    //获取用户进入管理页面的授权链接
    getAuthUrl: corpid => createAPI('/admin/v1/auth/auth-url?corpid=' + corpid, 'GET', {}),
    //企业微信第三方应用授权登录
    wwxThirdLogin: config => createAPI('/admin/v1/auth/wwx-third-login', 'POST', config),
  },

  // 管理员用户相关
  user: {
    add: config => createAPI('/admin/v1/users', 'POST', config),
    edit: config => createAPI('/admin/v1/users', 'PUT', config),
    del: id => createAPI('/admin/v1/users/' + id, 'DELETE', {}),

    //获取用户的信息
    getUserInfo: () => createAPI('/admin/v1/users/info', 'GET', {}),
    // 获取部门的用户信息
    getDeptUser: deptId => createAPI('/admin/v1/users/dept-user?dept_id=' + deptId, 'GET', {}),
    //获取当前用户的下属信息
    getSubordinate: config => createAPI('/admin/v1/users/subordinate', 'GET', config),
    //获取未处理的信息数据
    getUnprocessed: config => createAPI('/admin/v1/users/unprocessed', 'GET', config),
    //获取未处理的详细信息
    getUnprocessedInfo: config => createAPI('/admin/v1/users/unprocessed-info', 'GET', config),

    //验证密码
    validPass: pass => createAPI('/admin/v1/users/valid-pass?pass=' + pass, 'GET', {}),
    //修改密码
    updatePass: config => createAPI('/admin/v1/users/update-pass', 'PUT', config),
    //修改手机号
    updatePhone: config => createAPI('/admin/v1/users/update-phone', 'PUT', config),
    //修改用户信息
    updateUser: config => createAPI('/admin/v1/users/update-user', 'PUT', config),
    //修改头像信息
    updateAvatar: config => createAPI('/admin/v1/users/update-avatar', 'PUT', config),
  },

  // 角色管理
  role: {
    add: config => createAPI('/admin/v1/role', 'POST', config),
    edit: config => createAPI('/admin/v1/role', 'PUT', config),
    del: id => createAPI('/admin/v1/role/' + id, 'DELETE', {}),

    // 获取角色的用户信息
    getUser: roleId => createAPI('/admin/v1/role/get-user?role_id=' + roleId, 'GET', {}),
    // 保存角色的用户信息
    saveUser: config => createAPI('/admin/v1/role/save-user', 'POST', config),
    // 获取角色的菜单信息
    getMenu: roleId => createAPI('/admin/v1/role/get-menu?role_id=' + roleId, 'GET', {}),
    // 保存角色的菜单信息
    saveMenu: config => createAPI('/admin/v1/role/save-menu', 'POST', config),

    getRoleTree: config => createAPI('/admin/v1/role/tree', 'get', config),
  },

  // 用户基本权限操作
  permission: {
    add: config => createAPI('/admin/v1/permission', 'POST', config),
    edit: config => createAPI('/admin/v1/permission', 'PUT', config),
    del: id => createAPI('/admin/v1/permission/' + id, 'DELETE', {}),
    getPermissionTree: config => createAPI('/admin/v1/permission/tree', 'GET', config)
  },

  // 菜单管理
  menu: {
    add: config => createAPI('/admin/v1/menu', 'POST', config),
    edit: config => createAPI('/admin/v1/menu', 'PUT', config),
    del: id => createAPI('/admin/v1/menu/' + id, 'DELETE', {}),

    getMenusTree: config => createAPI('/admin/v1/menu/tree', 'GET', config)
  },

  // 配置项管理
  config: {
    list: config => createAPI('/admin/configure/list', 'POST', config),
    save: config => createAPI('/admin/configure/save', 'POST', config),
    delete: config => createAPI('/admin/configure/del', 'DELETE', config),

    getParamValue: config => createAPI('/admin/configure/param-value', 'POST', config)
  },
  // tab可配置配
  tabConfig: {
    add: config => createAPI('/admin/v1/config-tab', 'post', config),
    edit: config => createAPI('/admin/v1/config-tab', 'put', config),
    del: id => createAPI('/admin/v1/config-tab/' + id, 'delete', {}),
  },
  // Action可配置配
  actionConfig: {
    add: config => createAPI('/admin/v1/config-action', 'post', config),
    edit: config => createAPI('/admin/v1/config-action', 'put', config),
    del: id => createAPI('/admin/v1/config-action/' + id, 'delete', {}),
  },
  // 可视化配置
  visualDraggableConfig: {
    getDefaultConfig: config => createAPI('/admin/v1/config-corp/config', 'get', {}),
    getTabsConfig: config => createAPI('/admin/v1/config-corp?' + config, 'get', {}),
    delTabsConfig: config => createAPI('/admin/v1/config-corp/'+config, 'delete', {}),
    addTabsConfig: config => createAPI('/admin/v1/config-corp', 'post', config),
    putTabsConfig: config => createAPI('/admin/v1/config-corp', 'put', config),
    getDefaultTabsConfig: config => createAPI('/admin/v1/config-corp/tab', 'get', {}),
    getActionConfig: config => createAPI('/admin/v1/config-corp/action', 'get', {}),
    saveAction: config => createAPI('/admin/v1/config-corp/save-action', 'put', config),
    setTabSort: config => createAPI('/admin/v1/config-corp/tab-sort', 'post', config)
  },
}

export default permission
